package com.springcloud.auth.feign;

import com.springcloud.auth.config.OauthConfig;
import com.springcloud.auth.entity.TUserInfo;
import com.springcloud.auth.mapper.TUserInfoMapper;
import com.springcloud.auth.utils.OauthUtils;
import com.springcloud.commom.api.R;
import com.springcloud.commom.utils.RedisUtil;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@AllArgsConstructor
@Slf4j
public class AuthClient implements IAuthClient {

    private RedisUtil redis;

    private TUserInfoMapper userInfoMapper;

    @Override
    public R<Map<String,String>> getAccount(String accessToken) {
        String token = redis.get(OauthConfig.AUTH_ACCESS_TOKEN + accessToken);
        String userId = OauthUtils.getUserId(token);

        TUserInfo userInfo = userInfoMapper.selectById(userId);
        Map<String,String> map = new HashMap<>();
        map.put("account",userInfo.getUserName());

        return R.data(map);
    }
}
